//
//  TestViewController.swift
//  NewVersionDemo
//
//  Created by zeng on 2018/3/13.
//  Copyright © 2018年 youmy. All rights reserved.
//

import UIKit

fileprivate let kHomeRunonTopCellId = "kHomeRunonTopCellId"
fileprivate let kHomeRunonBottomCellId = "kHomeRunonBottomCellId"

fileprivate let kItemMargin:CGFloat = 1
fileprivate let kItemW:CGFloat = (UIScreen.main.bounds.width - 1 * kItemMargin) / 2

class TestViewController: UIViewController {
    
    @IBOutlet weak var baseView: UIView!
    lazy var collectionView:UICollectionView = {
        
        let kItemH:CGFloat = 195
        
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        layout.minimumLineSpacing = kItemMargin
        layout.minimumInteritemSpacing = kItemMargin
        layout.sectionInset = UIEdgeInsetsMake(kItemMargin, 0, 0, 0)
        
        let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 300), collectionViewLayout: layout)
        collectionView.backgroundColor = UIColor.groupTableViewBackground
        collectionView.delegate = self
        collectionView.dataSource = self
        
        collectionView.register(UINib.init(nibName: "YMHomeRunOnTopCell", bundle: nil), forCellWithReuseIdentifier: kHomeRunonTopCellId)
        
        collectionView.register(UINib.init(nibName: "YMHomeRunOnBottomCell", bundle: nil), forCellWithReuseIdentifier: kHomeRunonBottomCellId)
        
        return collectionView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let view = YMHomeRunOnView.nibView()
        self.view.addSubview(view)
    }

}
extension TestViewController:UICollectionViewDelegateFlowLayout{
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        if indexPath.section == 0 {
            let width = (UIScreen.main.bounds.width - kItemMargin) / 2
            return CGSize(width: width, height: 92)
        }else{
            let width = (UIScreen.main.bounds.width - 2 * kItemMargin) / 3
            return CGSize(width: width, height: 155)
        }
    }
}

extension TestViewController:UICollectionViewDataSource,UICollectionViewDelegate{
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 2
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if section == 1 {
            return 3
        }
        return 2
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        if indexPath.section == 0 {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kHomeRunonTopCellId, for: indexPath) as! YMHomeRunOnTopCell
            return cell
        }else{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kHomeRunonBottomCellId, for: indexPath) as! YMHomeRunOnBottomCell
            return cell
        }
    }
}
